home *** CD-ROM | disk | FTP | other *** search
/ PC Format (PL) 2015 August / PC_Format_082015.iso / Pełne wersje / F-Secure FREEDOME VPN 1.0.11 / Freedome.exe / QtGraphicalEffects / private / SourceProxy.qml < prev   
Text File  |  2015-04-13  |  5KB  |  137 lines

  1. /****************************************************************************
  2. **
  3. ** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
  4. ** Contact: http://www.qt-project.org/legal
  5. **
  6. ** This file is part of the Qt Graphical Effects module.
  7. **
  8. ** $QT_BEGIN_LICENSE:BSD$
  9. ** You may use this file under the terms of the BSD license as follows:
  10. **
  11. ** "Redistribution and use in source and binary forms, with or without
  12. ** modification, are permitted provided that the following conditions are
  13. ** met:
  14. **   * Redistributions of source code must retain the above copyright
  15. **     notice, this list of conditions and the following disclaimer.
  16. **   * Redistributions in binary form must reproduce the above copyright
  17. **     notice, this list of conditions and the following disclaimer in
  18. **     the documentation and/or other materials provided with the
  19. **     distribution.
  20. **   * Neither the name of Digia Plc and its Subsidiary(-ies) nor the names
  21. **     of its contributors may be used to endorse or promote products derived
  22. **     from this software without specific prior written permission.
  23. **
  24. **
  25. ** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  26. ** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  27. ** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  28. ** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  29. ** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  30. ** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  31. ** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  32. ** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  33. ** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  34. ** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  35. ** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
  36. **
  37. ** $QT_END_LICENSE$
  38. **
  39. ****************************************************************************/
  40.  
  41. import QtQuick 2.0
  42.  
  43. Item {
  44.     id: rootItem
  45.     property variant input
  46.     property variant output
  47.     property variant sourceRect
  48.     visible: false
  49.  
  50.     Component.onCompleted: evaluateInput()
  51.  
  52.     onInputChanged: evaluateInput()
  53.  
  54.     onSourceRectChanged: evaluateInput()
  55.  
  56.     function evaluateInput() {
  57.         if (input == undefined) {
  58.             output =  input
  59.         }
  60.         else if (sourceRect != undefined && sourceRect != Qt.rect(0, 0, 0, 0) && !isQQuickShaderEffectSource(input)) {
  61.             proxySource.sourceItem = input
  62.             output = proxySource
  63.             proxySource.sourceRect = sourceRect
  64.         }
  65.         else if (isQQuickItemLayerEnabled(input)) {
  66.             output = input
  67.         }
  68.         else if ((isQQuickImage(input) && !hasTileMode(input) && !hasChildren(input))) {
  69.             output = input
  70.         }
  71.         else if (isQQuickShaderEffectSource(input)) {
  72.             output = input
  73.         }
  74.         else {
  75.             proxySource.sourceItem = input
  76.             output = proxySource
  77.             proxySource.sourceRect = Qt.rect(0, 0, 0, 0)
  78.         }
  79.     }
  80.  
  81.     function isQQuickItemLayerEnabled(item) {
  82.         if (item.hasOwnProperty("layer")) {
  83.             var l = item["layer"]
  84.             if (l.hasOwnProperty("enabled") && l["enabled"].toString() == "true")
  85.                 return true
  86.         }
  87.         return false
  88.     }
  89.  
  90.     function isQQuickImage(item) {
  91.         var imageProperties = [ "fillMode", "progress", "asynchronous", "sourceSize", "status", "smooth" ]
  92.         return hasProperties(item, imageProperties)
  93.     }
  94.  
  95.     function isQQuickShaderEffectSource(item) {
  96.         var shaderEffectSourceProperties = [ "hideSource", "format", "sourceItem", "mipmap", "wrapMode", "live", "recursive", "sourceRect" ]
  97.         return hasProperties(item, shaderEffectSourceProperties)
  98.     }
  99.  
  100.     function hasProperties(item, properties) {
  101.         var counter = 0
  102.             for (var j = 0; j < properties.length; j++) {
  103.                 if (item.hasOwnProperty(properties [j]))
  104.                     counter++
  105.             }
  106.         return properties.length == counter
  107.     }
  108.  
  109.     function hasChildren(item) {
  110.         if (item.hasOwnProperty("childrenRect")) {
  111.             if (item["childrenRect"].toString() != "QRectF(0, 0, 0, 0)")
  112.                 return true
  113.             else
  114.                 return false
  115.         }
  116.         return false
  117.     }
  118.  
  119.     function hasTileMode(item) {
  120.         if (item.hasOwnProperty("fillMode")) {
  121.             if (item["fillMode"].toString() != "0")
  122.                 return true
  123.             else
  124.                 return false
  125.         }
  126.         return false
  127.     }
  128.  
  129.     ShaderEffectSource {
  130.         id: proxySource
  131.         live: rootItem.input != rootItem.output
  132.         hideSource: false
  133.         smooth: true
  134.         visible: false
  135.     }
  136. }
  137.